<?php

namespace app\store\controller;
use \Workerman\Worker;
use \Workerman\Lib\Timer;
use app\common\library\WsLog;
use think\Db;
use think\Log;

/**
 *  卖 出租客户到期重置
 */
class Customer{

}
$task = new Worker();
$task->onWorkerStart = function ($task) {
    $time_interval = 2;
    Timer::add($time_interval, function () {
        //获取卖，出租/跟进人id不为空客户/状态为跟进中/楼管录入的客户信息
        $toBeAssignedInfos=Db::name('love_customer')->where(['datatype'=>['in','2,3'],'status'=>1,'floweuserid'=>['>',0],'iszilu'=>2])
            ->field('id,datatype,floweuserid,iszilu,cityid,areaid,fenpei_time')->select()->toArray();
        if($toBeAssignedInfos){
            foreach ($toBeAssignedInfos as $k=>$v){
                if($v['fenpei_time']){
                    if((time()-$v['fenpei_time'])>345600){
                        Db::name('love_customer')->where(['id'=>$v['id']])->update(['status'=>1,'floweuserid'=>0,'fenpei_time'=>0,'update_time'=>time()]);
                        Log::mylog('测试日志：','被修改的销售id:'.$v['floweuserid'],'nunset-floweuserid');
                        Log::mylog('测试日志：','被修改的客户id:'.$v['id'],'nunset-customerid');
                        $logdata['userid']=0;
                        $logdata['datatype']=11;
                        $logdata['fenpeiid']=$v['floweuserid'];
                        $logdata['customerid']=$v['id'];
                        $logdata['fromType']=2;
                        $logdata['remark']='卖/出租客户系统重置';
                        $logdata['create_time']=time();
                        Db::name('love_log')->insert($logdata);
                        return true;
                    }else{
                        Log::mylog('测试日志：','时间未到数据id:'.$v['id'],'nunset-notimeout');
                        return false;
                    }
                }
            }
        }else{
            Log::mylog('未获取到客户日志(log)：','未获取到客户信息','unset');
            return false;
        }
    });
};
//运行worker
Worker::runAll();